package springdidemo.demos;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

@Controller//为什么要这个注解
public class UserController {
    //第一种Auto..注入
//    @Autowired
//    public UserService userservice;


    //构造方法注入
//    public UserService userservice;
//    public UserController(UserService userService){
//       this.userservice=userService;
//    }

    //set方法注入,Auto...注解是必须的
    @Autowired
    public UserService userservice;
    public void setUserservice(UserService userservice) {
        this.userservice = userservice;

    }

    public void say(){
        System.out.println("Hi controller");
        userservice.say();
    }
}
